package com.tjetc.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.DefaultClassMapper;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;

@Slf4j
public class RabbitConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        //消息 成功或失败 发送到交换机 都会回调
        //记录日志
        if (!ack)  log.info("交换机失败回调:{}",cause);
    }

    @Override
    public void returnedMessage(ReturnedMessage returnedMessage) {
        //消息发到队里失败 回调
        log.info("回调函数消息主题:{}",new String(returnedMessage.getMessage().getBody()));
        log.info("响应码:{}",returnedMessage.getReplyCode());
        log.info("回调描述：{}",returnedMessage.getReplyText());
        log.info("回调函数使用的交换机：{}",returnedMessage.getExchange());
        log.info("回调函数使用的路由键：{}",returnedMessage.getRoutingKey());
    }



}
